//
//  CZMainViewController.m
//  CY--OCweibo
//
//  Created by mac on 15/11/23.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZMainViewController.h"
#import "CZHomeViewController.h"
#import "CZDiscoverViewController.h"
#import "CZMessageViewController.h"
#import "CZProfileViewController.h"
@interface CZMainViewController ()

@property (nonatomic, strong) UIButton *composeButton;

@end

@implementation CZMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //首页
    
    self.tabBar.tintColor =[UIColor orangeColor];
    CZHomeViewController *homeVc = [[CZHomeViewController alloc] init];
    
    [self addChildViewController:homeVc Withtitle:@"首页" WithImage:@"tabbar_home"];
    //消息
    CZMessageViewController *messageVc = [[CZMessageViewController alloc] init];
    
    [self addChildViewController:messageVc Withtitle:@"消息" WithImage:@"tabbar_message_center"];
    
    //占位控制器
    
    [self addChildViewController:[[UIViewController alloc] init]];
    
    //发现
    CZDiscoverViewController *discoverVc = [[CZDiscoverViewController alloc] init];
    
    [self addChildViewController:discoverVc Withtitle:@"发现" WithImage:@"tabbar_discover"];
    //我的
    CZProfileViewController *profileVc = [[CZProfileViewController alloc] init];
    
    [self addChildViewController:profileVc Withtitle:@"我的" WithImage:@"tabbar_profile"];
    
    
    
}

- (void)addChildViewController:(UIViewController *)childController Withtitle:(NSString *)title  WithImage:(NSString *)imageName
{

    
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:childController];
    
    childController.title = title;
    
    childController.tabBarItem.image = [UIImage imageNamed:imageName];
    
    
    [self addChildViewController:homeNav];

}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    float width = self.tabBar.bounds.size.width / 5;
    
    self.composeButton.frame=CGRectMake(2 * width - 5, 0, width + 10, self.tabBar.bounds.size.height);
}
- (UIButton *)composeButton
{
    if (_composeButton==nil) {
        
    
    _composeButton = [[UIButton alloc] init];
    
    [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
    [self.tabBar addSubview:_composeButton];
        //添加点击事件
        [_composeButton addTarget:self action:@selector(composeClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _composeButton;
}
- (void)composeClick
{
    
    NSLog(@"点击了加号按钮");
}
@end
